'''
Created on 10 sept. 2012

@author: matthieu
'''
from bottle import template

def render_details(db_cursor, content_uid):
    db_cursor.execute("""SELECT * FROM texts WHERE content_uid=%s""" % (content_uid))
    return template("texts/details", data=db_cursor.fetchone())

def render_editor(db_cursor, content_uid):
    db_cursor.execute("""SELECT * FROM texts WHERE content_uid=%s""" % (content_uid))
    return template("texts/editor", content_uid=content_uid, data=db_cursor.fetchone())

def commit_update(db_cursor, request, uid):
    value = request.forms["value"]
    db_cursor.execute("""UPDATE texts SET value="%s" WHERE content_uid=%s""" % (value, uid))

    if len(value) > 12:
        return value[:12] + "..."
    else:
        return value